package com.wpp.testcommen;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class test {
    //创建一个通用工厂，来创建bean
    /*
    * 首先需要一个properties，存储全限定类名
    * */

    //在这读取文件，并且加载为对象
    public static Properties getProperties(){
        Properties properties = new Properties();
        InputStream inputStream = test.class.getClassLoader().getResourceAsStream("test.properties");
        try {
            properties.load(inputStream);
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }

    //传参数进来，才知道要加载哪个bean
    public static Object GetBeanTest(String name){
        Object o = null;
        String property = getProperties().getProperty(name);
        try {
            Class<?> aClass = Class.forName(property);//获取出来的值通过反射创建对象
            o = aClass.newInstance();

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return o;
    }




}
